using Abp.Application.Editions;
using Abp.Application.Features;
using Abp.Auditing;
using Abp.Authorization;
using Abp.Authorization.Users;
using Abp.EntityHistory;
using Abp.Localization;
using Abp.Notifications;
using Abp.Organizations;
using Abp.UI.Inputs;
using AutoMapper;
using DHJ.Cost.Auditing.Dto;
using DHJ.Cost.Authorization.Accounts.Dto;
using DHJ.Cost.Authorization.Permissions.Dto;
using DHJ.Cost.Authorization.Roles;
using DHJ.Cost.Authorization.Roles.Dto;
using DHJ.Cost.Authorization.Users;
using DHJ.Cost.Authorization.Users.Dto;
using DHJ.Cost.Authorization.Users.Profile.Dto;
using DHJ.Cost.Chat;
using DHJ.Cost.Chat.Dto;
using DHJ.Cost.CostBooking;
using DHJ.Cost.CostRecord.Dto;
using DHJ.Cost.Editions;
using DHJ.Cost.Editions.Dto;
using DHJ.Cost.Friendships;
using DHJ.Cost.Friendships.Cache;
using DHJ.Cost.Friendships.Dto;
using DHJ.Cost.Localization.Dto;
using DHJ.Cost.ManHours;
using DHJ.Cost.ManHours.Dto;
using DHJ.Cost.Models;
using DHJ.Cost.Models.Dto;
using DHJ.Cost.MultiTenancy;
using DHJ.Cost.MultiTenancy.Dto;
using DHJ.Cost.MultiTenancy.HostDashboard.Dto;
using DHJ.Cost.MultiTenancy.Payments;
using DHJ.Cost.MultiTenancy.Payments.Dto;
using DHJ.Cost.Notifications.Dto;
using DHJ.Cost.Organizations.Dto;
using DHJ.Cost.Report.Dto;
using DHJ.Cost.Reports;
using DHJ.Cost.Sessions.Dto;
using DHJ.Cost.SZ_Models;
using DHJ.Cost.SZ_Models.Dto;
using DHJ.Cost.Tasks;
using DHJ.Cost.Tasks.Dto;
using DHJ.Cost.TreeStructure;
using DHJ.Cost.TreeStructure.Dto;

namespace DHJ.Cost
{
    internal static class CustomDtoMapper
    {
        public static void CreateMappings(IMapperConfigurationExpression configuration)
        {
            //Inputs
            configuration.CreateMap<CheckboxInputType, FeatureInputTypeDto>();
            configuration.CreateMap<SingleLineStringInputType, FeatureInputTypeDto>();
            configuration.CreateMap<ComboboxInputType, FeatureInputTypeDto>();
            configuration.CreateMap<IInputType, FeatureInputTypeDto>()
                .Include<CheckboxInputType, FeatureInputTypeDto>()
                .Include<SingleLineStringInputType, FeatureInputTypeDto>()
                .Include<ComboboxInputType, FeatureInputTypeDto>();
            configuration.CreateMap<StaticLocalizableComboboxItemSource, LocalizableComboboxItemSourceDto>();
            configuration.CreateMap<ILocalizableComboboxItemSource, LocalizableComboboxItemSourceDto>()
                .Include<StaticLocalizableComboboxItemSource, LocalizableComboboxItemSourceDto>();
            configuration.CreateMap<LocalizableComboboxItem, LocalizableComboboxItemDto>();
            configuration.CreateMap<ILocalizableComboboxItem, LocalizableComboboxItemDto>()
                .Include<LocalizableComboboxItem, LocalizableComboboxItemDto>();

            //Chat
            configuration.CreateMap<ChatMessage, ChatMessageDto>();
            configuration.CreateMap<ChatMessage, ChatMessageExportDto>();

            //Feature
            configuration.CreateMap<FlatFeatureSelectDto, Feature>().ReverseMap();
            configuration.CreateMap<Feature, FlatFeatureDto>();

            //Role
            configuration.CreateMap<RoleEditDto, Role>().ReverseMap();
            configuration.CreateMap<Role, RoleListDto>();
            configuration.CreateMap<UserRole, UserListRoleDto>();

            //Edition
            configuration.CreateMap<EditionEditDto, SubscribableEdition>().ReverseMap();
            configuration.CreateMap<EditionSelectDto, SubscribableEdition>().ReverseMap();
            configuration.CreateMap<SubscribableEdition, EditionInfoDto>();

            configuration.CreateMap<Edition, EditionInfoDto>().Include<SubscribableEdition, EditionInfoDto>();

            configuration.CreateMap<Edition, EditionListDto>();
            configuration.CreateMap<Edition, EditionEditDto>();
            configuration.CreateMap<Edition, SubscribableEdition>();
            configuration.CreateMap<Edition, EditionSelectDto>();

            //Payment
            configuration.CreateMap<SubscriptionPaymentDto, SubscriptionPayment>().ReverseMap();
            configuration.CreateMap<SubscriptionPaymentListDto, SubscriptionPayment>().ReverseMap();
            configuration.CreateMap<SubscriptionPayment, SubscriptionPaymentInfoDto>();

            //Permission
            configuration.CreateMap<Permission, FlatPermissionDto>();
            configuration.CreateMap<Permission, FlatPermissionWithLevelDto>();

            //Language
            configuration.CreateMap<ApplicationLanguage, ApplicationLanguageEditDto>();
            configuration.CreateMap<ApplicationLanguage, ApplicationLanguageListDto>();
            configuration.CreateMap<NotificationDefinition, NotificationSubscriptionWithDisplayNameDto>();
            configuration.CreateMap<ApplicationLanguage, ApplicationLanguageEditDto>()
                .ForMember(ldto => ldto.IsEnabled, options => options.MapFrom(l => !l.IsDisabled));

            //Tenant
            configuration.CreateMap<Tenant, RecentTenant>();
            configuration.CreateMap<Tenant, TenantLoginInfoDto>();
            configuration.CreateMap<Tenant, TenantListDto>();
            configuration.CreateMap<TenantEditDto, Tenant>().ReverseMap();
            configuration.CreateMap<CurrentTenantInfoDto, Tenant>().ReverseMap();

            //User
            configuration.CreateMap<User, UserEditDto>()
                .ForMember(dto => dto.Password, options => options.Ignore())
                .ReverseMap()
                .ForMember(user => user.Password, options => options.Ignore());

            configuration.CreateMap<User, UserLoginInfoDto>();
            configuration.CreateMap<User, UserListDto>();
            configuration.CreateMap<User, ChatUserDto>();
            configuration.CreateMap<User, OrganizationUnitUserListDto>();
            configuration.CreateMap<CurrentUserProfileEditDto, User>().ReverseMap();
            configuration.CreateMap<UserLoginAttemptDto, UserLoginAttempt>().ReverseMap();

            //AuditLog
            configuration.CreateMap<AuditLog, AuditLogListDto>();
            configuration.CreateMap<EntityChange, EntityChangeListDto>();

            //Friendship
            configuration.CreateMap<Friendship, FriendDto>();
            configuration.CreateMap<FriendCacheItem, FriendDto>();

            //OrganizationUnit
            configuration.CreateMap<OrganizationUnit, OrganizationUnitDto>();

            /* ADD YOUR OWN CUSTOM AUTOMAPPER MAPPINGS HERE */

            //Cost
            configuration.CreateMap<ActualCost, ActualCostListDto>();
            configuration.CreateMap<DirectCost, DirectCostListDto>();
            configuration.CreateMap<DirectCost, YclCostListDto>();

            //Task
            configuration.CreateMap<Task, TaskDto>();
            configuration.CreateMap<Task, SimpleTaskDto>();
            configuration.CreateMap<Batch, BatchDto>();

            //Model
            configuration.CreateMap<Model, ModelListDto>();
            configuration.CreateMap<Model, ModelEditDto>().ReverseMap();
            configuration.CreateMap<Launch, LaunchListDto>();
            configuration.CreateMap<Launch, LaunchEditDto>().ReverseMap();
            configuration.CreateMap<Pici, PiciDto>().ReverseMap();


            //ManHour
            configuration.CreateMap<BatchManHour, BatchManHourListDto>()
                .ForMember(dto => dto.TaskId, options => options.MapFrom(mh => mh.Batch == null ? null : mh.Batch.Task == null ? null : mh.Batch.Task.TaskNum));
            //AssemRel
            configuration.CreateMap<AssemRel, AssemRelListDto>();
            configuration.CreateMap<FlatAssemRel, AssemRelListDto>();

            //TreeNodeBase
            configuration.CreateMap<TreeNodeBase, TreeNodeDto>()
                .ForMember(dto => dto.Data, options => options.MapFrom(l => l.NodeValue));
            configuration.CreateMap<TreeNodeBase, TreeNodeListDto>();
            //SzReport
            configuration.CreateMap<SzReport, SzReportEditDto>().ReverseMap();
            configuration.CreateMap<SzReport, SzReportListDto>();

            configuration.CreateMap<ChReport, ChReportEditDto>().ReverseMap()
               ;
            configuration.CreateMap<ChReport, ChReportListDto>();
        }
    }
}